package com.uwlaser.rest;

import com.uwlaser.annotation.Log;
import com.uwlaser.domain.CraftOperationProduct;
import com.uwlaser.service.CraftOperationProductService;
import com.uwlaser.service.dto.CraftOperationProductDto;
import com.uwlaser.service.dto.CraftOperationProductQueryParam;
import org.springframework.data.domain.Pageable;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.*;
import java.util.Set;

/**
* @author zk-Qin
* @date 2022-05-11
**/
@RestController
@RequiredArgsConstructor
@Api(tags = "工序产品关系表管理")
@RequestMapping("/api/craftOperationProduct")
public class CraftOperationProductController {

    private final CraftOperationProductService craftOperationProductService;

    @GetMapping
    @Log("查询工序产品关系表-分页")
    @ApiOperation("查询工序产品关系表-分页")
    @PreAuthorize("@el.check('craftOperationProduct:list')")
    public ResponseEntity query(CraftOperationProductQueryParam query, Pageable pageable){
        return new ResponseEntity<>(craftOperationProductService.queryAll(query,pageable),HttpStatus.OK);
    }

    @GetMapping("/list")
    @Log("查询工序产品关系表-列表")
    @ApiOperation("查询工序产品关系表-列表")
    @PreAuthorize("@el.check('craftOperationProduct:list')")
    public ResponseEntity list(CraftOperationProductQueryParam query){
        return new ResponseEntity<>(craftOperationProductService.queryAll(query),HttpStatus.OK);
    }

    @GetMapping("/getByProduct")
    @Log("查询产品关联的工序-列表")
    @ApiOperation("查询产品关联的工序-列表")
    @PreAuthorize("@el.check('craftOperationProduct:list')")
    public ResponseEntity getByProduct(CraftOperationProductQueryParam query){
        return new ResponseEntity<>(craftOperationProductService.getByProduct(query),HttpStatus.OK);
    }

    @PostMapping
    @Log("新增工序产品关系表")
    @ApiOperation("新增工序产品关系表")
    @PreAuthorize("@el.check('craftOperationProduct:add')")
    public ResponseEntity create(@Validated @RequestBody CraftOperationProductDto resources){
        return new ResponseEntity<>(craftOperationProductService.insert(resources),HttpStatus.CREATED);
    }

    @PutMapping
    @Log("修改工序产品关系表")
    @ApiOperation("修改工序产品关系表")
    @PreAuthorize("@el.check('craftOperationProduct:edit')")
    public ResponseEntity update(@Validated @RequestBody CraftOperationProductDto resources){
        craftOperationProductService.updateById(resources);
        return new ResponseEntity<>(HttpStatus.NO_CONTENT);
    }

    @DeleteMapping
    @Log("删除工序产品关系表")
    @ApiOperation("删除工序产品关系表")
    @PreAuthorize("@el.check('craftOperationProduct:del')")
    public ResponseEntity delete(@RequestBody Set<Integer> ids) {
        craftOperationProductService.removeByIds(ids);
        return new ResponseEntity<>(HttpStatus.OK);
    }

    /*
    @Log("导出工序产品关系表")
    @ApiOperation("导出工序产品关系表")
    @GetMapping(value = "/download")
    @PreAuthorize("@el.check('craftOperationProduct:list')")
    public void download(HttpServletResponse response, CraftOperationProductQueryParam query) throws IOException {
        craftOperationProductService.download(craftOperationProductService.queryAll(query), response);
    }*/

}
